This error appears randomly. I'm able to write and read the database file, but sometimes doesn't work, even with the same request.
I tried to test just one connection (to avoid multiple, thinking that could be the problem), and also randomly fails.
I checked the permissions of the file(windows), and all in order (if not I wouldn't be able to write the file)
This is the code to connect to database:
class Con{
private $pdo;
public function conex($db){
try{
// $pdo = $this->pdo;
if ($this->pdo == null){
sleep(0.1);
$this->pdo = new PDO("sqlite:../../content/engine/" . $db,"","",array(
PDO::ATTR_PERSISTENT => true
));
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return $this->pdo;
}catch(PDOException $e){
die( $e->getMessage());
} finally{
$this->pdo = null;
}
}
}
class Q_General extends Con{
protected $db;
public function __construct($db){
if ($this->db == null){
$this->db = $this->conex($db);
}
}
public function get_query($sql){
$query = $this->db->prepare($sql);
$query->execute();
$res = $query->fetchAll();
$query->closeCursor();
return $res;
}
}
I do the request with ajax, so I can control the number and order of request and setup a queue for every request with the purpose of avoid write or read at the same time.
Any clue what can I be doing wrong?